<template>
    <div class="saveUpdate">
        <el-dialog :close-on-click-modal="false" title="申请信用额度" :visible.sync="showDialog" @close="$emit('update:showUpdate', false)"
                   :showUpdate="showUpdate" width="500px">
            <el-form :model="DetailInfo" ref="saveChn" label-width="120px" size="mini">
                <dialog-wrapper :MaxWidth="400">
                    <el-form-item label="当前余额：">
                        <el-input v-model.number="balance" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="申请金额：" prop="amount"
                                  :rules="[{ required: true, message: '金额不能为空'},{ type: 'number', message: '金额必须为数字值'}]">
                        <el-input v-model.number="DetailInfo.amount" placeholder="将提交总代审核..."></el-input>
                    </el-form-item>
                </dialog-wrapper>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="$emit('update:showUpdate', false)" size="small">取 消</el-button>
                <el-button type="primary" :loading="loading" @click="saveDetail" size="small">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import DialogWrapper from '@/components/DialogWrapper'
    import {saveAgencyRecharge} from '@/api'
    import {useVcode} from '@/utils/CommonJs.js'

    export default {
        components: {DialogWrapper},
        data() {
            return {
                setbank: false,
                showDialog: this.showUpdate,
                loading: false,
                balance: this.$store.state.user.userinfo.balance / 100,
                DetailInfo: {}
            }
        },
        props: {
            showUpdate: {
                type: Boolean,
                default: false
            },
            id: {
                type: Number
            },
            MerchantType: {
                type: Object
            },
            settleCycle: {
                type: Object
            },
        },
        created() {
        },
        methods: {
            saveDetail() {
                useVcode(this, () => {
                    this.$refs.saveChn.validate(valid => {
                        if (valid) {
                            saveAgencyRecharge(Object.assign({}, this.DetailInfo, {amount: this.DetailInfo.amount * 100})).then(res => {
                                if (res.status === 0) {
                                    this.$message({message: '申请成功。', type: 'success'})
                                    this.$emit('update:showUpdate', false)
                                }
                            })
                        }
                    })
                })

            }
        },
        watch: {
            showUpdate() {
                this.showDialog = this.showUpdate
            }
        }
    }
</script>
